﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace BitPortal.Utils
{
    public static class SEOHelper
    {
        /// <summary>
        /// Chuyen chuoi unicode sang khong unicode
        /// </summary>
        /// <param name="accented"></param>
        /// <returns></returns>
        public static string ToStringRejexMarks(this string accented)
        {
            Regex regex = new Regex(@"\p{IsCombiningDiacriticalMarks}+");
            string strFormD = accented.Normalize(System.Text.NormalizationForm.FormD);
            return regex.Replace(strFormD, String.Empty).Replace("Đ", "D").Replace("đ", "d");
        }

        /// <summary>
        /// Tao chuoi than thien voi SEO
        /// </summary>
        /// <param name="inputStr"></param>
        /// <returns></returns>
        public static string ToSeoString(this string inputStr)
        {
            return ToStringRejexMarks(inputStr).Replace("  "," ").Replace(" ","-").Replace("/","").Replace("\\","").Replace("&","").ToLower();
        }
    }
}
